import java.util.Stack;

public class Multime implements Structura {
	int nr_elem;

	Stack<Integer> sir = new Stack<Integer>();

	public Multime(int nr_elem) {
		this.nr_elem = nr_elem;
	}

	public void adauga(int elem) {
		sir.add(elem);
	}

	public void sterge(int elem) {
		if (sir.contains(elem)) {
			sir.removeElementAt(sir.indexOf(elem));
		} else {
			System.out.println("Elementul nu exista in multime !!!");
		}
	}

	public void reuniune(Multime m1, Multime m2) {
		System.out.println();
		System.out.println("Reuniune");
		System.out.println();
		for (int j = 0; j < sir.size(); j++) {
			for (int i = 0; i < m2.sir.size(); i++) {
				if (m1.sir.contains(m2.sir.elementAt(i))) {
					m2.sir.removeElementAt(i);
				}
			}
		}
		for (int i = 0; i < m2.sir.size(); i++) {
			m1.sir.add(m2.sir.elementAt(i));
		}
		System.out.println("Rezultatul reuniunii este multime : "
				+ m1.toString());
	}

	public String toString() {
		return sir.toString();
	}
}
